package com.knife.cachev2.service.impl;

import com.knife.cache.redis.helper.RedisCache;
import com.knife.cachev2.infra.init.RedisCacheInitiator;
import com.knife.cachev2.service.KnifeCacheV2Service;
import com.knife.common.utils.KnifeSpringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import java.util.Map;
import java.util.Objects;

/**
 * @author lth
 * @created 2025年08月01日 星期五 14:15
 */
@Service
public class KnifeCacheV2ServiceImpl implements KnifeCacheV2Service {

    @Override
    public void reloadCache() {
        Map<String, RedisCacheInitiator> map = KnifeSpringUtil.getApplicationContext().getBeansOfType(RedisCacheInitiator.class);
        for (Map.Entry<String, RedisCacheInitiator> entry : map.entrySet()) {
            RedisCacheInitiator value = entry.getValue();
            value.init();
        }
    }

    @Override
    public void removeCache() {
        Map<String, RedisCacheInitiator> map = KnifeSpringUtil.getApplicationContext().getBeansOfType(RedisCacheInitiator.class);
        for (Map.Entry<String, RedisCacheInitiator> entry : map.entrySet()) {
            RedisCacheInitiator value = entry.getValue();
            value.clear();
        }
    }
}
